package team.hyznrj.studentsys.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.hyznrj.studentsys.dto.PowerDto;
import team.hyznrj.studentsys.dto.ResultDto;
import team.hyznrj.studentsys.entity.account.key.PowerFunctionTableKey;
import team.hyznrj.studentsys.service.PowerService;
import team.hyznrj.studentsys.utils.ResultUtil;

/**
 * @author ReMidDream
 * @date 2018-05-09 12:36
 **/
@Api(value = "PowerController", description = "操作权限接口")
@RestController
@RequestMapping("/power")
public class PowerController {

    @Autowired
    private PowerService powerService;

    @ApiOperation(value="查询权限下的所有角色")
    @GetMapping("fAllPower")
    public ResultDto<?> findAllPower(){
        return ResultUtil.Success(powerService.findAllPowerDto());
    }


    @ApiOperation(value="添加/更新 操作以及功能关系", notes="*传入参数只需要带中文解释的")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "powerId", value = "操作权限ID",paramType = "query"),
            @ApiImplicitParam(name = "powerName", value = "操作权限",paramType = "query"),
            @ApiImplicitParam(name = "functionInfoList[0].functionId", value = "功能IDS <br>测试只能单个<br> JS传数组",paramType = "query"),
    })
    @PostMapping("/iuPower")
    public ResultDto<?> insertPower(PowerDto powerDto){
        powerService.insertUpdatePower(powerDto);
        return ResultUtil.Success();
    }


    @ApiOperation(value="添加 操作与功能关系")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pftPowerId", value = "操作权限ID",paramType = "query"),
            @ApiImplicitParam(name = "pftFunctionId", value = "功能ID",paramType = "query")
    })
    @PostMapping("/iuPowerFunction")
    public ResultDto<?> insertPowerFunction(PowerFunctionTableKey powerFunctionTableKey){
        powerService.insertRelationshipBetweenPowerAndFunction(powerFunctionTableKey);
        return ResultUtil.Success();
    }


    @ApiOperation(value="删除 操作与功能关系")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pftPowerId", value = "操作权限ID",paramType = "query"),
            @ApiImplicitParam(name = "pftFunctionId", value = "功能ID",paramType = "query")
    })
    @PostMapping("/dPowerFunction")
    public ResultDto<?> deletePowerFunction(PowerFunctionTableKey powerFunctionTableKey){
        powerService.deleteRelationshipBetweenPowerAndFunction(powerFunctionTableKey);
        return ResultUtil.Success();
    }

    @ApiOperation(value="删除 操作权限以及功能关系")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "powerId", value = "操作权限ID",paramType = "query"),
    })
    @PostMapping("/dPower")
    public ResultDto<?> deletePower(String powerId){
        powerService.deletePower(powerId);
        return ResultUtil.Success();
    }

}
